package com.atguigu.test.rabbitmq.controller;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Controller;

import java.io.IOException;

@Controller
@RabbitListener(queues = "two-java-queue")
public class AccentMQ {
    @RabbitHandler
    public void accentMQ(User user, Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        if (deliveryTag%2==0){
            System.out.println(deliveryTag+"接受了"+user);
            channel.basicAck(deliveryTag,false);
        }else {
            System.out.println(deliveryTag+"没签收"+user.toString());
            channel.basicNack(deliveryTag,false,true);
        }
    }
}
